//
//  IDVertifyViewController.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/11.
//

#import "IDVertifyViewController.h"
#import "IDCardTableViewCell.h"
#import "SectionHeadView.h"
#import "IdentifyCardController.h"

#define kTabCell    @"kTabCell"

@interface IDVertifyViewController ()

@property (nonatomic) NSMutableArray *headAry;

@end

@implementation IDVertifyViewController

- (void)back{
    TipsAlertWLView *wl = [[TipsAlertWLView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [[UIApplication sharedApplication].keyWindow addSubview:wl];
    wl.clickSureBlock = ^{
        [[self getCurrentVC] jumpToPopControlClass:@"OrderDetailViewController"];
    };
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    self.isTableViewStyleGrouped = YES;
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"E-KYC";
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 55)];
    self.tableView.tableHeaderView = headView;
    
    UILabel *lab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:15] color:[UIColor colorWithHexString:@"#022D06"]];
    lab.frame = CGRectMake(15, 0, kScreenWidth, 55);
    lab.text = @"Select An ID To Verify Your Identity";
    [headView addSubview:lab];
    
    NSArray *arr = @[
        @{
            @"name":@"Recommended ID Type",
            @"isShow":@(YES),
        },
        @{
            @"name":@"Other Options",
            @"isShow":@(YES),
        }
    ];
    self.headAry = [[NSMutableArray alloc] init];
    self.headAry = [SectionHeadModel mj_objectArrayWithKeyValuesArray:arr];
    
    [self loadData];
    
    [self.tableView registerClass:[IDCardTableViewCell class] forCellReuseIdentifier:kTabCell];
    [self.tableView reloadData];
}

- (void)loadData{
    
    [self.data addObjectsFromArray:self.ocrCardArr];
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SectionHeadModel *model  = self.headAry[section];
    if (!model.isShow) {
        return 0;
    }
    return [self.data[section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    IDCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTabCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    cell.backImgView.image = [UIImage imageNamed:@"icon_ver3"];
    if (indexPath.row == [self.data[indexPath.section] count] - 1) {
        cell.backImgView.image = [UIImage imageNamed:@"icon_ver4"];
    }
    
    cell.nameLab.text = esString(self.data[indexPath.section][indexPath.row]);
    cell.iconV.image = [UIImage imageNamed:@"icon_rightArrow"];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DLog(@"======%@",self.data[indexPath.section][indexPath.row]);
    
    IdentifyCardController *vc = [[IdentifyCardController alloc] init];
    vc.cardStr = esString(self.data[indexPath.section][indexPath.row]);
    vc.idStr = esString(self.idStr);
    [self.navigationController pushViewController:vc animated:YES];
    
    [CreditServerHelper uploadMaiDianDataStartTimeStr:self.startTimeStr andEndTimeStr:[NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"] withTypeStr:@"2" withFirmly:esString(self.idStr) withSmaller:esString([[NSUserDefaults standardUserDefaults] valueForKey:kOrderNumber])];
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    SectionHeadView *headV = [[SectionHeadView alloc] init];
    
    SectionHeadModel *mm = self.headAry[section];

    headV.titleLab.text = esString(mm.name);
    
    headV.clickTapBlock = ^{
        
        mm.isShow = !mm.isShow;
        [self.tableView reloadData];
    };
    
    if (mm.isShow == YES) {
        
        headV.arrowIconV.image = [UIImage imageNamed:@"icon_down"];
        headV.backImgV.image = [UIImage imageNamed:@"icon_ver2"];
    
    }else{
        
        headV.arrowIconV.image = [UIImage imageNamed:@"icon_up"];
        headV.backImgV.image = [UIImage imageNamed:@"icon_ver1"];
    
    }
    
    
    
    return headV;
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    SectionHeadModel *mm = self.headAry[section];
    if (!mm.isShow) {
        return 64;
    } 
    return 48;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footV = [[UIView alloc] init];
    return footV;;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 20;
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
